package org.example.sportdemo.service;

import org.example.sportdemo.entity.CompetitionOrder;
import org.example.sportdemo.entity.ProductOrder;
import org.example.sportdemo.mapper.CompetitionOrderMapper;
import org.example.sportdemo.mapper.ProductOrderMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ProductOrderService {

    @Autowired
    private ProductOrderMapper productOrderMapper;

    public List<ProductOrder> selectAll(){
        return productOrderMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<ProductOrder> groundList = productOrderMapper.selectAll();
        //总条数
        Integer totalCount = productOrderMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,groundList);
    }

    public void addProductOrder(ProductOrder productOrder) {

        Date date = new Date();
        productOrder.setInsert_time(date);
        productOrderMapper.addProductOrder(productOrder);

    }

    public ProductOrder selectById(Integer id) {
        return productOrderMapper.selectById(id);
    }

    public void updateProductOrder(ProductOrder productOrder) {
        productOrderMapper.updateProductOrder(productOrder);
    }

    public void deleteByIds(Integer[] ids) {
        productOrderMapper.deleteByIds(ids);
    }
}
